import sys
from blspy import AugSchemeMPL, G1Element, PrivateKey
from chia.util.keychain import Keychain, bytes_to_mnemonic, generate_mnemonic, unlocks_keyring,bip39_word_list,mnemonic_to_seed
from chia.wallet.derive_keys import master_sk_to_farmer_sk, master_sk_to_pool_sk, master_sk_to_wallet_sk

keychain: Keychain = Keychain()


userMnemonic=sys.argv[1]
userSearchCondition=sys.argv[2].split("=")


if(userMnemonic.find("?") == -1):
	print("Please use ? replace missing words")

keyWordList=bip39_word_list().splitlines()

for index in range(len(keyWordList)):
	testWord=keyWordList[index]
	print(str(index)+"/"+str(len(keyWordList))+" "+testWord)

	testMne = userMnemonic.replace("?",testWord)
	seed=mnemonic_to_seed(testMne,"")
	key=AugSchemeMPL.key_gen(seed)

	if(userSearchCondition[0] == 'fingerPrint'):
		print(key.get_g1().get_fingerprint())
		if(key.get_g1().get_fingerprint() == int(userSearchCondition[1])):
			print("the result is:"+testWord)
			break

	